home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Awards / MacUser Shareware Awards 94 / System Enhancements / 1. KeyQuencer 1.2 / Developer’s toolkit / Extension code / Action.c < prev    next >
Text File  |  1994-07-18  |  3KB  |  75 lines

  1. //==============================================================================
  2. // DOCUMENTATION AVAILABLE IN THE EXTENSION.H AND ACTION.H HEADERS
  3.  
  4. #include "Extension.h"
  5. #include "Action.h"
  6.  
  7. Handle    gTextResource;
  8.  
  9. //==============================================================================
  10. // THIS ROUTINE IS CALLED WHEN THE EXTENSION IS INVOKED BY A MACRO
  11.  
  12. short run(ParamsPtr params, MachineHandle mac, GluePtr glue)
  13. {
  14.     // This is where the extension does its work
  15.     // cur heap zone = active app heap, cur res file = unknown
  16.     // the extension file is closed, resources are not available
  17.     
  18.     StringPtr    string;
  19.     long        length;
  20.     short        index;
  21.     Str255        message;
  22.     
  23.     message[0] = 0;                                                        // clear message string
  24.     for(index=0; index<params->paramsCount; ++index)                    // scan all params
  25.     {
  26.         string = params->parameter[index];                                // get nth parameter
  27.         if(string[1]=='"' && string[0]>2)                                // check for quotes
  28.         {
  29.             if(message[0]>0) return kTellTooManyParams;                    // we only accept one parameter
  30.             BlockMoveData(&string[2], &message[1], (long)string[0]-2);    // copy text, strip quotes
  31.             message[0] = string[0]-2;
  32.         }
  33.         else if(EqualString("\pLOADED", string, false, true))            // check for "loaded" keyword
  34.         {
  35.             if(message[0]>0) return kTellTooManyParams;                    // again, no more than 1 param
  36.             if(gTextResource==0L)                                        // 'TEXT' 128 not found
  37.             {
  38.                 (*glue->DisplayMessage)("\ptext resource not found at startup.", true);
  39.                 return kExtGenericError;
  40.             }
  41.             length = GetHandleSize(gTextResource);                        // get text length
  42.             if(length>255) length = 255;                                // max length of our string
  43.             BlockMoveData(*gTextResource, &message[1], length);            // copy to message string
  44.             message[0] = (unsigned char)length;
  45.         }
  46.         else return kTellUnknownKeyword;                                // unknown keyword found
  47.     }
  48.     if(message[0]==0) return kTellNotEnoughParams;                        // didn't find required parameter
  49.     
  50.     (*glue->DisplayMessage)(message, false);                            // display our message
  51.     return kExtNoError;                                                    // we're done
  52. }
  53.  
  54. //==============================================================================
  55. // THIS ROUTINE IS CALLED ONCE AT STARTUP TIME
  56.  
  57. short init(MachineHandle mac, GluePtr glue)
  58. {
  59.     // This is only called once at startup time
  60.     // cur heap zone = sys heap, cur res file = extension res file
  61.     // you may load (and detach) resources and initialize your data
  62.     // glue is only available in recent versions, check for nil glue
  63.     
  64.     gTextResource = Get1Resource('TEXT', 128);                            // load resource
  65.     if(gTextResource)
  66.     {
  67.         HNoPurge(gTextResource);                                        // make it unpurgeable
  68.         DetachResource(gTextResource);                                    // res file will be closed soon
  69.     }
  70.     if(glue) (*glue->ShowStartupIcon)(128);                                // show our own icon (no glue was available in KQ 1.0)
  71.     return kExtNoError;                                                    // everything OK
  72. }
  73.  
  74. //==============================================================================
  75.